package com.nacos.controller.feign;

import com.feign.client.NacosConsumerClient;
import com.feign.entity.Params;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者: 林江
 * @创建时间: 2023/10/26
 * @功能:
 */
@RestController
public class NacosFeignConsumerController {

    @Autowired
    NacosConsumerClient nacosConsumerClient;

    /**
     * 基于带有负载均衡的 FeignClient 来访问服务提供方
     *
     * @return
     */
    @RequestMapping("/consumer02")
    public String consumer02() {
        String data = nacosConsumerClient.test();
        return "访问到的数据：" + data;
    }

    @RequestMapping("/consumer03")
    public String consumer03() {
        Params params = new Params();
        params.setName("林江");
        params.setAge(24);
        String data = nacosConsumerClient.test01(params);
        return "访问到的数据：" + data;
    }

    @RequestMapping("/consumer04")
    public String consumer04() {
        Params params = new Params();
        params.setName("林江");
        params.setAge(24);
//        String data = nacosConsumerClient.test02(new HashMap<String, Object>() {{
//            put("name", "林江");
//            put("age", "24");
//        }});
        return "访问到的数据：" + nacosConsumerClient.test02(params);
    }

    @RequestMapping("/consumer05")
    public String consumer05() {
        return "访问到的数据：" + nacosConsumerClient.test03();
    }
}
